#include <iostream>
#include <vector>
using namespace std;

using vec2 = vector<vector<int>>;

void dfs(vec2 &gh, vector<int> &vw, vector<vector<long>> &sum, int u, int p, int k)
{
	sum[u][0] = vw[u];
	for (auto v : gh[u]) {
		if (v != p) {
			dfs(gh, vw, sum, v, u, k);
			for (int i = 1; i <= k; i++) {
				sum[u][i] += sum[v][i - 1];
			}
		}
	}
}

void dfs2(vec2 &gh, vector<int> &vw, vector<vector<long>> &sum, vector<vector<long>> &dp, int u, int p, int k)
{
	for (auto v : gh[u]) {
		if (v != p) {
			dp[v][0] = vw[v];
			dp[v][1] = sum[v][1] + vw[u];
			for (int i = 2; i <= k; i++) {
				dp[v][i] = sum[v][i] + dp[u][i - 1] - sum[v][i - 2];
			}
			dfs2(gh, vw, sum, dp, v, u, k);
		}
	}
}

int main()
{
	int n = 0, k = 0;
	cin >> n >> k;
	vector<vector<int>> gh(n + 1);
	vector<int> vw(n + 1, 0);
	vector<vector<long>> sum(n + 1, vector<long>(k + 1, 0)), dp(sum);
	for (int i = 0, u, v; i < n - 1; i++) {
		cin >> u >> v;
		gh[u].push_back(v);
		gh[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) {
		cin >> vw[i];
	}
	dfs(gh, vw, sum, 1, 0, k);
	dp[1] = sum[1];
	dfs2(gh, vw, sum, dp, 1, 0, k);
	for (int i = 1; i <= n; i++) {
	        int ans = 0;
	        for(int j = 0; j <= k; j++){
	                ans += dp[i][j];
	        }
		cout << ans << endl;
	}
	return 0;
}